﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="ST._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>

    <script type="text/javascript" language="javascript">
        function SearchSuccess(res, destCtrl) {
            document.getElementById("Buttons").setAttribute("visible",true);
            var params = { allowScriptAccess: "always" };
            var atts = { id: "myytplayer" };
            videos = res;
            nextVidID = Math.floor(Math.random() * (videos.length + 1));
            currentVidId = videos[nextVidID].url;
            document.getElementById("currentVid").innerHTML = videos[nextVidID].fullname;
            var url = "http://www.youtube.com/v/" + currentVidId + "?enablejsapi=1&playerapiid=ytplayer";
            ytplayer = document.getElementById("myytplayer");
            
            if(firstSearch){
                swfobject.embedSWF(url, "ytapiplayer", "425", "356", "8", null, null, params, atts);
                firstSearch = false;
            }
            else
            {
                ytplayer.cueVideoById(currentVidId,0,"default");
                ytplayer.playVideo();
            }       
            hist[0] = videos[nextVidID].url;
        //    alert(" first push:");
        //    alert(videos[nextVidID].url);
        //    alert("in array: "+hist[0]);
        }
        
        function embed (videoId, videoTitle) {
//            document.getElementById("Buttons").setAttribute("visible",true);
            var params = { allowScriptAccess: "always" };
            var atts = { id: "myytplayer" };
            ytplayer = document.getElementById("myytplayer");
            currentVidId = videoId;
            document.getElementById("currentVid").innerHTML = videoTitle;
            var url = "http://www.youtube.com/v/" + videoId + "?enablejsapi=1&playerapiid=ytplayer";
            document.getElementById("Buttons").style.display="inline";
            swfobject.embedSWF(url, "ytapiplayer", "425", "356", "8", null, null, params, atts);
//            document.getElementById("GridView1").setAttribute("Visible",false);
            document.getElementById("DivTable").style.display="none";
            
            
        }
    </script>

</head>
<body><center>
    <form id="form1" runat="server" onprerender="OnPreRender">
    
        <asp:Panel ID="PanelSearch" runat="server">
            <br />
            <%--<input type= "text" id="startpoint" size="80" onkeydown="if (event.keyCode == 13) document.getElementById('Button1').click()"/>
      <button id="Button1" onclick="search()" title="GO"
          type="button">
          BONANZA
      </button>--%>
            <asp:TextBox runat="server" ID="TextBoxSearch" Width="599px" onkeydown="if (event.keyCode == 13) document.getElementById('<%=ButtonSearch.ClientID%>').click()"></asp:TextBox>
            <asp:Button runat="server" ID="ButtonSearch" Text="BONANZA" OnClick="ButtonSearch_Click1" />
        </asp:Panel>

        <script type="text/javascript" src="swfobject.js"></script>

        <div runat="server" id="DivTable">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowCommand="GridView1_RowCommand"
                OnRowDataBound="GridView1_RowDataBound" AllowPaging="True" OnPageIndexChanging="GridView1_OnPageIndexChanging">
                <AlternatingRowStyle BackColor="#f0f0f0" />
                <Columns>
                    <%--<asp:ButtonField ButtonType="Button" Text="This one" CommandName="ThisVideo" />--%>
                    <asp:ImageField DataImageUrlField="thumbnailUrl" HeaderText="Preview image">
                    </asp:ImageField>
                    <asp:BoundField DataField="title" HeaderText="Title" />
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:HiddenField ID="hidden" runat="server" Value='<%#Eval("videoId") %>' />
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>
        </div>
        <div runat="server" id="ytapiplayer">
            <p>
            </p>
        </div>
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true" />
    
    </form>
    <div runat="server" id="Buttons">
        <%--<asp:Panel runat="server" ID="PanelPlayerButtons">--%>
        <button onclick="Next()">
            Next</button>
        <button onclick="Prev()" id="ButtonPrevious">
            Previous</button>
        <br />
        <table>
            <tr>
                <td>
                    Current Video Is:
                </td>
                <td id="currentVid">
                </td>
            </tr>
            <tr>
                <td>
                    Next Video Is:
                </td>
                <td id="nextVidTitle">
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <button id="changenext" title="Change Next" onclick="ButtonChangeNextChanged()" />
                    Change Next
                </td>
            </tr>
        </table>
        <%--</asp:Panel>--%>
    </div></center>
</body>
</html>
